﻿using RemoteSensingImageDirectServer.Models.Request.Response;
using RemoteSensingImageDirectServer.Service.Common;
using Microsoft.AspNetCore.Mvc;
using RemoteSensingImageDirectServer.Models.Request.Params.OGC.RasterMap;

namespace RemoteSensingImageDirectServer.Controllers.V1
{
    public class RasterMapController : Controller
    {
        /// <summary>
        /// 栅格地图服务
        /// </summary>
        private readonly IRasterMapService _rasterMapService;

        public RasterMapController(IRasterMapService rasterMapService)
        {
            this._rasterMapService = rasterMapService;
        }

        [HttpGet]
        [Route("raster/single/v1/wmts")]
        public async Task<object> GetSingleRasterMap(SingleWMTSParams @params)
        {
            var backgroundTask = Task.Factory.StartNew<object>(() =>
            {
                if (!ModelState.IsValid)
                {
                    return BadRequest(ModelState);
                }

                var serviceResult = _rasterMapService.GetData(@params);

                if (serviceResult.Code == 0)
                {
                    return serviceResult.Data;
                }
                else
                {
                    return serviceResult;
                }
            });
            await backgroundTask;

            var result = backgroundTask.Result;

            return result;
        }


        [HttpGet]
        [Route("raster/single/v1/wms")]
        public async Task<object> GetSingleRasterMap(SingleWMSParams @params)
        {
            var backgroundTask = Task.Factory.StartNew<object>(() =>
            {
                if (!ModelState.IsValid)
                {
                    return BadRequest(ModelState);
                }

                var serviceResult = _rasterMapService.GetData(@params);

                if (serviceResult.Code == 0)
                {
                    return serviceResult.Data;
                }
                else
                {
                    return serviceResult;
                }
            });
            await backgroundTask;

            var result = backgroundTask.Result;

            return result;
        }

        [HttpGet]
        [Route("raster/group/v1/wmts")]
        public async Task<object> GetGroupRasterMap(GroupWMTSParams @params)
        {
            var backgroundTask = Task.Factory.StartNew<object>(() =>
            {
                if (!ModelState.IsValid)
                {
                    return BadRequest(ModelState);
                }

                var serviceResult = _rasterMapService.GetData(@params);

                if (serviceResult.Code == 0)
                {
                    return serviceResult.Data;
                }
                else
                {
                    return serviceResult;
                }
            });
            await backgroundTask;

            var result = backgroundTask.Result;

            return result;
        }


        [HttpGet]
        [Route("raster/group/v1/wms")]
        public async Task<object> GetGroupRasterMap(GroupWMSParams @params)
        {
            var backgroundTask = Task.Factory.StartNew<object>(() =>
            {
                if (!ModelState.IsValid)
                {
                    return BadRequest(ModelState);
                }

                var serviceResult = _rasterMapService.GetData(@params);

                if (serviceResult.Code == 0)
                {
                    return serviceResult.Data;
                }
                else
                {
                    return serviceResult;
                }
            });
            await backgroundTask;

            var result = backgroundTask.Result;

            return result;
        }
    }
}
